﻿#include "verticalfoldablewidget.h"
#include "ui_verticalfoldablewidget.h"

VerticalFoldableWidget::VerticalFoldableWidget(FoldDirection direction, const QString& title, QWidget *parent) :
    QWidget(parent),
    ui(new Ui::VerticalFoldableWidget),
    m_direction(direction)
{
    ui->setupUi(this);
    //根据不同的方向，button显示不同的图片
    switch(m_direction)
    {
    case FoldLeft:
        ui->pushButton->setIcon(QIcon(":/pic/fold_right.png"));
        break;
    case FoldRight:
        ui->pushButton->setIcon(QIcon(":/pic/fold_left.png"));
    }
    setTitle(title);
}

void VerticalFoldableWidget::setTitle(const QString& title)
{
    ui->titleLabel->setText(title.split("",QString::SkipEmptyParts).join("\n"));
}

void VerticalFoldableWidget::setControlWidget(QWidget *controlWidget)
{
    m_controlWidget = controlWidget;
}

void VerticalFoldableWidget::setParternWidget(QWidget *parternWidget)
{
    m_parternWidget = parternWidget;
}

VerticalFoldableWidget::~VerticalFoldableWidget()
{
    delete ui;
}

//隐藏自己和包含自己的那一个dockwidget。显示折叠前的dockwidget
void VerticalFoldableWidget::on_pushButton_clicked()
{
    if(m_controlWidget && m_parternWidget)
    {
        m_controlWidget->hide();
        this->hide();
        m_parternWidget->show();
    }
}
